package com.dk.controller;

import com.dk.pojo.TabChangeImg;
import com.dk.pojo.TabSeller;
import com.dk.service.CarouselService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * 轮播图
 */
@Controller
@RequestMapping("carouselController")
public class CarouselController {
    @Autowired
    CarouselService carouselService;

    @RequestMapping("getInfo")
    @ResponseBody
    public List<TabChangeImg> getInfo() {
        return carouselService.getInfo();
    }

    @RequestMapping("toAdd")
    public String toAdd() {
        return "carousel/add";
    }

    @RequestMapping("insertInfo")
    @ResponseBody
    public boolean insertInfo(TabChangeImg changeImg) {
        int i = carouselService.insertInfo(changeImg);
        return i > 0;
    }

    @RequestMapping("toUpdate/{id}")
    public String toUpdate(@PathVariable("id") Integer id, Model model) {
        TabChangeImg changeImg = carouselService.getInfoById(id);
        model.addAttribute("changeImg", changeImg);
        return "carousel/update";
    }
    @RequestMapping("updateCarousel")
    @ResponseBody
    public boolean updateCarousel(TabChangeImg changeImg){
        int i = carouselService.updateCarousel(changeImg);
        return i>0;
    }

    @RequestMapping("deleteCarouselById/{id}")
    @ResponseBody
    public boolean deleteSellerById(@PathVariable("id")Integer id){
        int i = carouselService.deleteCarouselById(id);
        return i>0;
    }
}
